﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Pku.BookStore.Web.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            IServices.ICategoryServices categoryDal = new Services.CategoryServices();
            IServices.IPublisherServices publisherDal = new Services.PublisherServices();
            IServices.IProductServices productDal = new Services.ProductServices();

            #region 分类
            Model.CategoryParam param = new Model.CategoryParam();
            param.Level = 1;
            param.PageNo = 1;
            param.PageRow = 2000;
            param.pCatid = 0;
            var cateList = categoryDal.Search(param);

            var CateList = new List<Models.CategoryModels>();
            foreach (var item in cateList)
            {
                param.Level = 2;
                param.pCatid = item.CategoryID;
                var pcateList = categoryDal.Search(param);
                var catem = new Models.CategoryModels();
                catem.CategoryID = item.CategoryID;
                catem.CategoryName = item.CategoryName;
                catem.pList = pcateList;
                CateList.Add(catem);
            }
            #endregion

            #region 品牌出版商
            Model.PublisherParam publisrParam = new Model.PublisherParam();
            publisrParam.PageNo = 1;
            publisrParam.PageRow = 50;
            var publisherList = publisherDal.Search(publisrParam);
            #endregion

            #region 新书速递
            Model.ProductParam productParam = new Model.ProductParam();
            productParam.PageNo = 1;
            productParam.PageRow = 4;
            productParam.isSpecial = 0;
            var productListNew = productDal.Search(productParam);

            productParam.isSpecial = 1;
            var productListSpecial = productDal.Search(productParam);
            #endregion

            #region 热售
            var productHot = productDal.GetSaleHot(7, 0);
            #endregion

            IDictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("CateList", CateList);
            dic.Add("publisherList", publisherList);
            dic.Add("productListNew", productListNew);
            dic.Add("productListSpecial", productListSpecial);
            dic.Add("productHot", productHot);

            return View(dic);
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
